home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Mac OS / Apple Guide / Engineering / Context Check Modules / Strip Modules CC / StripModule.c next >
Encoding:
C/C++ Source or Header  |  1994-05-02  |  2.8 KB  |  122 lines  |  [TEXT/KAHL]

  1. /****************************************/
  2.     
  3. /*    StripModule.c                        */
  4. /*    Author:             Shemin Gau, IP    */
  5. /*    Revision History:    03/24/94        */
  6.  
  7. /****************************************/
  8.  
  9.  
  10. #include <Files.h>
  11. #include <string.h>
  12. #include <Memory.h>
  13. #include <ToolUtils.h>
  14. #include <Errors.h>
  15. #include <Packages.h>
  16. #include <Types.h>
  17. #include <OSUtils.h>
  18.  
  19.  
  20. OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize);
  21.  
  22.  
  23. pascal OSErr main(Str255 msg, Size inSize, void* outMessage, Size* outSize, Handle ignoreMe)
  24. {    
  25.     SysEnvRec        theWorld;
  26.     CInfoPBRec        pBlck;
  27.     short            volID;
  28.     char            pathName[256] ;
  29.     char            cDummy[128] ;
  30.     Str255            pasDummy;    
  31.     
  32.     char            *str_holder = '\0';
  33.     char            *retstr = '\0';    
  34.     char            *ctemp1;
  35.     char            *ctemp7;
  36.     StringPtr        ptemp1;    
  37.     FInfo            fi;
  38.     
  39.     OSErr        myErr = noErr;
  40.     Boolean        result = false;
  41.     
  42.     
  43.     pathName[0] = '\0';
  44.     cDummy[0] = '\0';
  45.     pasDummy[0] = '\0';
  46.     
  47.     if (SysEnvirons(2, &theWorld)) {
  48.         result = false;
  49.         myErr = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
  50.         return(myErr);
  51.     } else {
  52.         volID = theWorld.sysVRefNum;
  53.     }
  54.  
  55.     /* set up pBlck stuff */
  56.     pBlck.dirInfo.ioNamePtr = pasDummy;
  57.     pBlck.dirInfo.ioVRefNum = volID;
  58.     pBlck.dirInfo.ioFDirIndex = 1;
  59.     pBlck.dirInfo.ioDrDirID = 0;
  60.     
  61.     /* get the first directory ID (if we can't, then errorback. */
  62.     if ( PBGetCatInfo(&pBlck, false) != noErr ) {
  63.         result = false;
  64.         myErr = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
  65.         return(myErr);
  66.     }
  67.  
  68.     /* now, keep going up the tree things we reach the top */
  69.     while (pBlck.dirInfo.ioDrDirID != 2) {
  70.         /* swap id's from the parent ID to the current ID and reset the index. */
  71.         pBlck.dirInfo.ioDrDirID = pBlck.dirInfo.ioDrParID;
  72.         pBlck.dirInfo.ioFDirIndex = -1;
  73.         /* get load the NamePtr (which is equal to pasDummy) and build the C string. */
  74.         if (!PBGetCatInfo(&pBlck, false)) {
  75.             ctemp1 = p2cstr(pasDummy);
  76.             strcpy(cDummy, ctemp1);
  77.             strcat(cDummy, ":");
  78.             strcat(cDummy, pathName);
  79.             strcpy(pathName, cDummy);
  80.         } else {
  81.             /* this is just in case the PB call fails.  */
  82.             result = false;
  83.             myErr = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
  84.             return(myErr);
  85.         }
  86.     }    
  87.  
  88.     ctemp7 = p2cstr(msg);
  89.     strcat(pathName, ctemp7);
  90.     
  91.     //now, convert the whole pathname into pascal string
  92.     ptemp1 = c2pstr(pathName);
  93.         
  94.     if (GetFInfo(ptemp1, 0, &fi) != noErr) {
  95.         result = false;
  96.         myErr = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
  97.         return(myErr);
  98.     } else {
  99.         result = true;
  100.         myErr = SetContextResult(&result, sizeof(Boolean), outMessage, outSize);
  101.         return(myErr);
  102.     }
  103.         
  104. }
  105.  
  106.  
  107. OSErr SetContextResult(void* theData, Size theSize, Ptr* outMessage, Size* outSize)
  108. {
  109.     Ptr    p;
  110.     
  111.     if (p = NewPtr(theSize)) {
  112.         BlockMove(theData, p, theSize);
  113.         
  114.         *outSize = theSize;
  115.         *outMessage    = p;
  116.         
  117.         return(noErr);
  118.     } else {
  119.         return(MemError());
  120.     }
  121. }
  122.